package com.hnit.mapper;


import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.hnit.web.bean.User;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

/**
 * 用户 Mapper 接口，继承 BaseMapper 获得基础 CRUD 方法
 */
@Mapper
public interface UserMapper extends BaseMapper<User> {
    // 无需编写基础方法，MyBatis-Plus 已默认实现
    // 可在此添加自定义查询方法（如根据用户名查询：User selectByUname(String uname);）
    //根据uname查找用户
    @Select("SELECT * FROM user WHERE userName = #{userName}")
    User findByUsername(String userName);

    @Select("SELECT * FROM user WHERE mobile = #{mobile}")
    User selectByMobile(String mobile);

    //根据uid查找用户
    @Select("SELECT * FROM user WHERE userID = #{userId}")
    User findByUid(Long userID);

    //更新用户信息
    @Update("UPDATE user SET userName=#{userName},userPassword=#{userPassword},mobile=#{mobile},email=#{email},avatar=#{avatar},gender=#{gender} WHERE userId=#{userId}")
    int updateUser(User user);

    //注销账号
    @Update("UPDATE user SET userStatus=0 WHERE userId=#{userId}")
    int deleteUser(Long userId);
}
